package xin.yangshuai.activemqproducertopic.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Topic;
import java.util.UUID;

/**
 * TopicProducer
 *
 * @author shuai
 * @date 2020/6/25
 */
@Component
public class TopicProducer {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Topic topic;

    //间隔时间定投
    @Scheduled(fixedDelay = 3000)  //间隔时间3秒钟定投
    public void produceTopicScheduled() {
        String payload = "*****Scheduled主题消息：" + UUID.randomUUID().toString().substring(0, 6);
        jmsMessagingTemplate.convertAndSend(topic, payload);
        System.out.println(payload);
    }

}
